<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>  
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>电子签章合同列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div style="display:none;">
	   <input name="prjId" id="prjId" type="text" class="ui-textbox" value="${prjId}"/>
	   <!-- 权限控制 -->
	   <sys:funcAuth resCd="reCreateCont">
	   		<input name="reCreateContId" id="reCreateContId" type="text" class="ui-textbox" value="1"/>
	   		<input name="delContId" id="delContId" type="text" class="ui-textbox" value="1"/>
	   </sys:funcAuth>
</div>
<div class="sqPanel">
      <div class="sqPanel_head">
          <div class="btnsBox">
          <c:if test="${ pianflag != '101'}">
	          <sys:FlowFrmAth preTaskIds="${preTaskIds}" athCd="addContract" pInstId="${pInstId}">
	              <span id="chooseCst" class="sq-button sq-button-round"  onclick="openDownConPage()">项目合同模板导出</span>
			  </sys:FlowFrmAth>
		</c:if>	  
           </div>
     </div>
      
	<div class="sqPanel_head inL">
	    <span>合同信息</span>
	</div>
	<!-- 开票申请列表 -->
	<div id="filEsignListGrid" class="sq-grid"></div> 
</div>
</div>

<script type="text/javascript">
    var grid = null, menu = null;
    var _prjId = $("#prjId").val();
    function openDownConPage(){
        $.ligerDialog.open({title: '项目合同模板导出',height: 500,width: 850, 
        	url: '<%=path%>/extcon/sysExpTmpl/toExtConPage.do?prjId='+_prjId
        });
	}
    $(function () {
        grid = $("#filEsignListGrid").ligerGrid({
            url: '<%=path%>/project/cont/initList.do?pianflag=${pianflag}&prjId='+_prjId,
            method: 'get',
            columns: [
                {display: '合同名称', name: 'contractNm', width: 140, align: 'center', enabledSort: false},
                {display: '业务系统编号', name: 'contractCode', width: 210, align: 'center', enabledSort: false},
                {display: '电子签章合同编号', name: 'contractNo', width: 210, align: 'center', enabledSort: false
                },
                {display: '合同状态', name: 'signSts', width: 180, align: 'center', enabledSort: false,
                	render:function (rowdata, rowindex, value, column) {
                		if(value != null && value == 1){
                			return '已签署';
                		}
						if((value != null && value == 0)){
                			return '未签署';
                		}
                	}		
                },
                {display: '创建时间', name: 'crtTm', width: 180, align: 'center',render:renderDate},
                {display:'事业部',name:'orgNm', width: 110, align: 'center', <c:if test="${pianflag == '101'}">hide:true ,</c:if> enabledSort: false,},
                {display: '操作', name: 'filePath', width: 280, align: 'left', enabledSort: false, 
                	render:function (rowdata, rowindex, value, column) {
                		var h = "";
                		if(value != null && value != ''){
                			h += '<a class="sq-button-hasicon" target="_downPdf'+rowdata.id+'" href="'+ value+'" ><i class=\"sqBtnIco_32\"></i>查看PDF</a>';
                		}
                		<c:if test="${pianflag != '101'}">
                		
                		var reCreateContId = $("#reCreateContId").val();
                		if(StringUtils.isNotEmpty(reCreateContId) && reCreateContId == 1){
                			 h+='<a class="sq-button-hasicon" href="javascript:reCreateCont(';
                             h+="'"+rowdata.id+"'";
                             h+=",'"+rowdata.filId+"'";
                             h+=","+rowdata.signSts+"";
                             h+=")\"><i class=\"sqBtnIco_28\"></i>"+UIUtils.showColumnTip("重新生成", "生成前请务必确认无误后在生成。")+"</a>";
                		}
                		var delContId = $("#delContId").val();
                		if(StringUtils.isNotEmpty(delContId) && delContId == 1){
               			 	h+='<a class="sq-button-hasicon" href="javascript:delCont(';
                            h+="'"+rowdata.id+"'";
                            h+=",'"+rowdata.filId+"'";
                            //h+=","+rowdata.signSts+"";
                            h+=")\"><i class=\"sqBtnIco_28\"></i>"+UIUtils.showColumnTip("作废合同", "您确定要作废此合同吗？")+"</a>";
               		}
                		</c:if>
                		return h;
                	}	
                }
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            rownumbers:true,
            frozen: false,
            allowUnSelectRow: true,
            alternatingRow: false,
            onBeforeShowData: function (row)
            {	
                var grid = this;
                grid.collapsedRows = [];
            },
            isShowDetailToggle:function (row)
            {
            	if(row.audStsCd == CommonConstant.C_AUD_NO_HAPPEN_CODE || 
            			row.audStsCd == CommonConstant.C_AUD_ADNWAY_CODE){
            		return false;
            	}
            	
            	return true;
            },
            detail: {
                height: 'auto',
                onShowDetail: showDetail_grid
            }
        });
        grid.setHeight(100);
    });
    
    //这里filId只作为一个记录, 不能作为实际查询业务数据使用,因为合同那边存的都是项目ID，没有区分支付表的ID, 但是在咱们自己业务系统中存入与合同之间的关系却分项目ID和支付表ID
    //如果用这个filId去查数据,支付表的数据就查不出来了。    电子合同那边是因为要一起签署一组的合同,所以一次都用了项目的ID去作为业务的主键,那边有用合同号和支付表号区分数据
    function reCreateCont(_contId, _filId, _signSts){
    	var tip = "";
    	if(_signSts == 1){
    		tip = "合同已经签署是否确定重新生成?";
    	}else{
    		tip = "是否确定重新生成?";
    	}
    	//alert(_contId + " - " + _filId);
    	$.ligerDialog.SQconfirm(tip, function (flag) {
			if(flag == false)return;
			var _url = "<%=path%>/project/cont/reCreateCont.do";
			AjaxUtils.ajaxPost(_url, {contId:_contId, filId:_filId}, function(msg){
				if(msg.success == 1){
					UIUtils.alertSuccess(msg.info);
					reLoadGrid();
				 }else{
					 UIUtils.alertError(msg.info);
				 }
			},true);
		});
    }
    
    function delCont(_contId, _filId){
    	$.ligerDialog.SQconfirm("您确定要废除此合同吗？", function (flag) {
			if(flag == false)return;
			var _url = "<%=path%>/project/cont/delCont.do";
			AjaxUtils.ajaxPost(_url, {contId:_contId, filId:_filId}, function(msg){
				if(msg.success == 1){
					UIUtils.alertSuccess(msg.info);
					reLoadGrid();
				 }else{
					 UIUtils.alertError(msg.info);
				 }
			},true);
		});
    }
    
    
    //重新加载Grid
    function reLoadGrid(){
    	/* var form = liger.get("searchBar");
        var data = form.getData();
        for (name in data) {
            grid.setParm(name, data[name]);
        } */
        grid.reload();
    }

    //逾期明细列表
    function showDetail_grid(row, detailPanel, callback){
        var gridBox = document.createElement('div');
        $(gridBox).css('margin', 10);
        $(detailPanel).css({
            'padding': 10,
            'box-sizing': 'border-box'
        }).append(gridBox);
        detailGrid = $(gridBox).ligerGrid({
            url: '<%=path%>/project/cont/searchDetailList.do?filSignId='+row.id,
            method: 'get',
            columns: [
                {display: '角色',name: 'signRole',width: 180,align:'center'},
                {display: '姓名',name: 'signName',width: 150,align:'center'},
                <c:if test="${pianflag != '101'}">
                {display: '电话', name: 'signNm', width: 180, align: 'center'},
                </c:if>
                {display: '签署状态', name: 'signStsName', width: 180, align: 'center'},
                {display: '签署时间', name: 'sucTm', width: 180, align: 'center',render:renderDate}
            ],
            root: 'rows',
            hideLoadButton : true,
            width: '100%',
            height: 'auto',
            isScroll: false,
            rownumbers:true,  //显示序号
            allowUnSelectRow:true,
            alternatingRow: false,
            onAfterShowData: callback,
            frozen: false,
            usePager: false
        });
    }        		
	
    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }
</script>

</body>
</html>